// INTEL

AddCSLuaFile( "shared.lua" )
AddCSLuaFile( "cl_init.lua" )
include( 'shared.lua' )

ENT.eSound = Sound("items/spawn_item.wav")

ENT.vo = {
	Sound("intel/vo/i_ahh.mp3"),
	Sound("intel/vo/i_ball.mp3"),
	Sound("intel/vo/i_cheese.mp3"),
	Sound("intel/vo/i_home.mp3"),
	Sound("intel/vo/i_hover.mp3"),
	Sound("intel/vo/i_lonly.mp3"),
	Sound("intel/vo/i_sobio.mp3"),
	Sound("intel/vo/i_trap.mp3")
}

function PlayerSetIntel( pl )
pl.intel = true
end

function ENT:SpawnFunction( ply, tr )

	if ( !tr.Hit ) then return end
	
	local SpawnPos = tr.HitPos + tr.HitNormal * 10
	
	local ent = ents.Create( "intel" )
	ent:SetPos( SpawnPos )
	ent:Spawn()
	ent:Activate()
	
	return ent
	
end

function ENT:Initialize()

	self.Entity:SetModel( "models/flag/briefcase.mdl"  )
	self.Entity:PhysicsInit( SOLID_VPHYSICS )
	self.Entity:SetMoveType( MOVETYPE_FLY )
	self.Entity:SetSolid( SOLID_VPHYSICS )
	
	local phys = self.Entity:GetPhysicsObject()
	if (phys:IsValid()) then
		phys:Wake()
	end
	
	timer.Create("Tdeath"..tostring(math.Rand(0,15000))..tostring(CurTime()/10),0.8,0, function()
		if ValidEntity(self.Entity) then
			local vPoint = self.Entity:GetPos() + Vector(0,0,1)
			local effectdata = EffectData()
			effectdata:SetOrigin( vPoint )
			effectdata:SetScale( 1 )
			util.Effect( "intel_magic", effectdata )
			self.Entity:EmitSound( "buttons/blip1.wav" ,70,100)
		end	
	end)
	
	timer.Create("Voice"..tostring(CurTime()/10),7,0, function()
		if ValidEntity(self.Entity) then
			self.Entity:EmitSound( self.Entity.vo[math.random(1,#self.Entity.vo)] , 200 ,100 )
		end	
	end)
	
	timer.Create("Tdelete_death"..tostring(math.Rand(0,10000))..tostring(CurTime()/10),180,1, function()
		if ValidEntity(self.Entity) then
			local vPoint = self.Entity:GetPos() + Vector(0,0,1)
			local effectdata = EffectData()
			effectdata:SetOrigin( vPoint )
			effectdata:SetScale( 1 )
			effectdata:SetStart(self.Entity:GetVelocity())
			util.Effect( "intel_magic", effectdata )
			self.Entity:Remove()
		end	
	end)
end

function ENT:Think()
	self.Entity:SetPos(self.Entity:GetPos() + Vector(0,0,math.sin(CurTime()*2)*0.1))
	self.Entity:SetAngles(self.Entity:GetAngles() + Angle(0,0.4,0) )
	
	self.Entity:NextThink( CurTime() + 0.001 )
	return true 
end

function ENT:PhysicsCollide( data, physobj )	
//NADA
end

function ENT:OnTakeDamage( dmginfo )

	self.Entity:TakePhysicsDamage( dmginfo )
	
end

function ENT:Touch( entidadeTocada )
	if !ValidEntity(entidadeTocada) then return end
	if !entidadeTocada:IsPlayer() or (entidadeTocada.intel == true) then return end
	
	self.Entity:EmitSound(self.Entity.eSound,200,100)
	
	PlayerSetIntel( entidadeTocada )
	
	if ValidEntity(self.Entity) then
		local vPoint = self.Entity:GetPos() + Vector(0,0,1)
		local effectdata = EffectData()
		effectdata:SetOrigin( vPoint )
		effectdata:SetScale( 0.7 )
		effectdata:SetStart(self.Entity:GetVelocity())
		util.Effect( "intel_magic", effectdata )--s
		self.Entity:Remove()
	end	

end



